<!DOCTYPE html>
<html lang="en-us">
<head>
	<meta charSet="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<link rel="apple-touch-icon" sizes="57x57" href="/CsvHelper/favicons/apple-icon-57x57.png" />
	<link rel="apple-touch-icon" sizes="60x60" href="/CsvHelper/favicons/apple-icon-60x60.png" />
	<link rel="apple-touch-icon" sizes="72x72" href="/CsvHelper/favicons/apple-icon-72x72.png" />
	<link rel="apple-touch-icon" sizes="76x76" href="/CsvHelper/favicons/apple-icon-76x76.png" />
	<link rel="apple-touch-icon" sizes="114x114" href="/CsvHelper/favicons/apple-icon-114x114.png" />
	<link rel="apple-touch-icon" sizes="120x120" href="/CsvHelper/favicons/apple-icon-120x120.png" />
	<link rel="apple-touch-icon" sizes="144x144" href="/CsvHelper/favicons/apple-icon-144x144.png" />
	<link rel="apple-touch-icon" sizes="152x152" href="/CsvHelper/favicons/apple-icon-152x152.png" />
	<link rel="apple-touch-icon" sizes="180x180" href="/CsvHelper/favicons/apple-icon-180x180.png" />
	<link rel="icon" type="image/png" sizes="192x192" href="/CsvHelper/favicons/android-icon-192x192.png" />
	<link rel="icon" type="image/png" sizes="32x32" href="/CsvHelper/favicons/favicon-32x32.png" />
	<link rel="icon" type="image/png" sizes="96x96" href="/CsvHelper/favicons/favicon-96x96.png" />
	<link rel="icon" type="image/png" sizes="16x16" href="/CsvHelper/favicons/favicon-16x16.png" />
	<link rel="manifest" href="/CsvHelper/manifest.json" />
	<meta name="msapplication-TileColor" content="#ffffff" />
	<meta name="msapplication-TileImage" content="/ms-icon-144x144.png" />
	<meta name="theme-color" content="#ffffff" />
	<title>V23 | CsvHelper</title>

	
	
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.1/css/bulma.min.css" />
	
	<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/default.min.css" />
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/vs.min.css" />
	<link rel="stylesheet" href="/CsvHelper/styles/index.css" />

	<script defer src="https://use.fontawesome.com/releases/v5.14.0/js/all.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
</head>
<body>
	<header id="header" class="header">
	<nav class="navbar is-light">
		<div class="navbar-brand">
			<a class="navbar-item" href="/CsvHelper">
				<img src="/CsvHelper/images/logo.svg" width="66" height="28" />
			</a>
			<div id="navbar-burger" class="navbar-burger">
				<span></span>
				<span></span>
				<span></span>
			</div>
		</div>
		<div id="navbar-menu" class="navbar-menu">
			<div class="navbar-start">
				<a class="navbar-item" href="/CsvHelper/getting-started">Getting Started</a>
				<a class="navbar-item" href="/CsvHelper/examples">Examples</a>
				<a class="navbar-item" href="/CsvHelper/migration">Migration</a>
				<a class="navbar-item" href="/CsvHelper/change-log">Change Log</a>
			</div>
			<div class="navbar-end">
				<a class="navbar-item" href="https://twitter.com/JoshClose">
					<span class="icon">
						<i class="fab fa-twitter"></i>
					</span>
				</a>
				<a class="navbar-item" href="https://github.com/JoshClose/CsvHelper">
					<span class="icon">
						<i class="fab fa-github"></i>
					</span>
				</a>
			</div>
		</div>
	</nav>
</header>


	<main id="main" class="container is-fluid">
		<div class="columns is-variable is-1">
				<div class="column">
					<div class="content">
						<h1 id="migrating-from-version-22-to-23">Migrating from version 22 to 23</h1>
<h2 id="csvconfiguration">CsvConfiguration</h2>
<p>All the constructor parameters were removed in favor of using
property setters. Apply this change to any of the options.</p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture, delimiter = &quot;;&quot;);

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	Delimiter = &quot;;&quot;,
};
</code></pre>
<h2 id="delegates">Delegates</h2>
<p>All delegates now take in a single struct argument.</p>
<p><strong>BadDataFound</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	BadDataFound = (field, context) =&gt; 
	{
		Console.WriteLine($&quot;field: {field}&quot;);
		Console.WriteLine($&quot;context: {context}&quot;);
	},
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	BadDataFound = args =&gt;
	{
		Console.WriteLine($&quot;field: {args.Field}&quot;);
		Console.WriteLine($&quot;context: {args.Context}&quot;);
	},
};
</code></pre>
<p><strong>ConvertFromString</strong></p>
<pre><code class="language-cs">// v22
Map(m =&gt; m.Property).Convert(row =&gt; row.GetField(0));

// v23
Map(m =&gt; m.Property).Convert(args =&gt; args.Row.GetField(0));
</code></pre>
<p><strong>ConvertToString</strong></p>
<pre><code class="language-cs">// v22
Map(m =&gt; m.Property).Convert(value =&gt; value.ToString());

// v23
Map(m =&gt; m.Property).Convert(args =&gt; args.Value.ToString());
</code></pre>
<p><strong>GetConstructor</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	GetConstructor = classType =&gt; classType.GetConstructors().First(),
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	GetConstructor = args =&gt; args.ClassType.GetConstructors().First(),
};
</code></pre>
<p><strong>GetDynamicPropertyName</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	GetDynamicPropertyName = (fieldIndex, context) =&gt; $&quot;Field{fieldIndex}&quot;;
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	GetDynamicPropertyName = args =&gt; $&quot;Field{args.FieldIndex}&quot;,
};
</code></pre>
<p><strong>HeaderValidated</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	HeaderValidated = (invalidHeaders, context) =&gt; Console.WriteLine($&quot;Invalid headers count: {invalidHeaders.Count}&quot;),
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	HeaderValidated = args =&gt; Console.WriteLine($&quot;Invalid headers count: {args.InvalidHeaders.Count}&quot;),
};
</code></pre>
<p><strong>MissingFieldFound</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	MissingFieldFound = (headerNames, index, context) =&gt; Console.WriteLine($&quot;Missing field: {headerNames[0]}&quot;),
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	MissingFieldFound = args =&gt; Console.WriteLine($&quot;Missing field: {args.HeaderNames[0]}&quot;),
};
</code></pre>
<p><strong>PrepareHeaderForMatch</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	PrepareHeaderForMatch = (header, fieldIndex) =&gt; header.ToLower(),
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	PrepareHeaderForMatch = args =&gt; args.Header.ToLower(),
};
</code></pre>
<p><strong>ReadingExceptionOccurred</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ReadingExceptionOccurred = exception =&gt;
    {
        Console.WriteLine(exception.Message);
        throw args.Exception;
    },
};
// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ReadingExceptionOccurred = args =&gt;
    {
        Console.WriteLine(args.Exception.Message);
        throw args.Exception;
    },
};
</code></pre>
<p><strong>ReferenceHeaderPrefix</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ReferenceHeaderPrefix = (memberType, memberName) =&gt; $&quot;{memberName}.&quot;,
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ReferenceHeaderPrefix = args =&gt; $&quot;{args.MemberName}.&quot;,
};
</code></pre>
<p><strong>ShouldQuote</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ShouldQuote = (field, fieldType, row) =&gt; true,
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ShouldQuote = args =&gt; true,
};
</code></pre>
<p><strong>ShouldSkipRecord</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ShouldSkipRecord = (records) =&gt; record.Length == 0,
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    ShouldSkipRecord = args =&gt; args.Record.Length == 0,
};
</code></pre>
<p><strong>ShouldUseConstructorParameters</strong></p>
<pre><code class="language-cs">// v22
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	ShouldUseConstructorParameters = type =&gt; true;
};

// v23
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	ShouldUseConstructorParameters = args =&gt; true;
};
</code></pre>
<p><strong>Validate</strong></p>
<pre><code class="language-cs">// v22
Map(m =&gt; m.Property).Validate(field =&gt; !string.IsNullOrEmpty(field));

// v23
Map(m =&gt; m.Property).Validate(args =&gt; !string.IsNullOrEmpty(args.Field));
</code></pre>

					</div>
				</div>
		</div>
	</main>

	<br /><br />

	<footer id="footer" class="footer">
	<div class="has-text-centered">&copy; 2009-2024 Josh Close</div>
</footer>



	<script>
		hljs.configure({
			tabReplace: "    "
		});
		hljs.initHighlightingOnLoad();
	</script>
	<script src="/CsvHelper/scripts/header.js"></script>
	<script src="/CsvHelper/scripts/sidebar.js"></script>
	
</body>
</html>
